package com.example.alibabanacosdiscoveryclient.controller;

import com.example.alibabanacosdiscoveryclient.domain.Test;
import com.example.alibabanacosdiscoveryclient.service.OrderService;
import com.example.alibabanacosdiscoveryclient.service.StorageService;
import com.example.alibabanacosdiscoveryclient.service.TestService;
import io.seata.spring.annotation.GlobalTransactional;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author:guoq
 * @date:2024/11/18
 * @descripion:
 */
@RestController
@Slf4j
@RequestMapping("/seata")
@Tag(name="seata的demo")
public class SeataController {
    @Autowired
    StorageService storageService;
    @Autowired
    OrderService orderService;
    @Autowired
    TestService testService;
    @GetMapping("/business")
    @Operation(summary ="业务处理")
    @GlobalTransactional
    public String business(String userId, String commodityCode, int orderCount) throws Exception {
        storageService.deduct(commodityCode, orderCount);
        orderService.create(userId, commodityCode, orderCount);
//        testService.insert(new Test("zs"));
        return "success";
    }

    @GetMapping("/list")
    @Operation(summary ="获取订单list")
    public String list()  {
        orderService.queryList().stream().forEach(item-> System.out.println(item.toString()));
        return "success";
    }
}
